//
//  IndexTableviewCell.m
//  CarTown
//
//  Created by 熊浩 on 15/8/1.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "IndexTableviewCell.h"
#import "CarDetailmodel.h"
#import <UIImageView+WebCache.h>


@interface IndexTableviewCell()
@property (weak, nonatomic) IBOutlet UIImageView *icon;
@property (weak, nonatomic) IBOutlet UILabel *titlename;
@property (weak, nonatomic) IBOutlet UILabel *dinapu;
@property (weak, nonatomic) IBOutlet UIImageView *renzheng;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titlewith;
@property (weak, nonatomic) IBOutlet UILabel *price;
@property (weak, nonatomic) IBOutlet UILabel *time;
@property (weak, nonatomic) IBOutlet UIImageView *yikoujia;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *yikou_width;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *yikou_height;


@end
@implementation IndexTableviewCell

- (void)awakeFromNib {
//        self.titlename.font=[UIFont systemFontOfSize:x5SFontSize+3];
//        self.dinapu.font=[UIFont systemFontOfSize:x5SFontSize];
//        self.time.font=[UIFont systemFontOfSize:x5SFontSize];
//        self.price.font=[UIFont systemFontOfSize:x5SFontSize+3];
        self.yikou_width.constant=36;
        self.titlewith.constant=160;
    
//        self.titlename.font=[UIFont systemFontOfSize:XotherFontSize+1];
//        self.dinapu.font=[UIFont systemFontOfSize:XotherFontSize];
//        self.time.font=[UIFont systemFontOfSize:XotherFontSize];
//        self.price.font=[UIFont systemFontOfSize:XotherFontSize+1];
    if (XHScreenwidth>320) {
        
  
        self.titlewith.constant=215;
    }
    // Initialization code
}
-(void)setCarmodel:(CarDetailmodel *)carmodel{
    _carmodel=carmodel;
    self.titlename.text=_carmodel.car_name;
    
   self.time.text=[NSDate dateStrFromTimeStr:_carmodel.addtime];
   NSString *pic=
     [NSString stringWithFormat:@"%@%@",websitehosturl,[_carmodel.brand_logo stringByReplacingCharactersInRange:NSRangeFromString(@"./") withString:@"/"]];
    [self.icon sd_setImageWithURL:[NSURL URLWithString:pic] placeholderImage:[UIImage imageNamed:@"placehoder"]];
    if ([_carmodel.is_price integerValue]==0) {
        self.yikoujia.hidden=NO;
    }else{
         self.yikoujia.hidden=YES;
    }
    NSString *pricestr=[NSString stringWithFormat:@"%@万",_carmodel.sysprice];
    if ([_carmodel.is_price integerValue]!=2) {
         self.price.text=pricestr;
    }else{
        self.price.text=@"电议";
    }
   
     CGSize maxszie=CGSizeMake(MAXFLOAT, MAXFLOAT);
    NSMutableParagraphStyle *contentgraphStyle = [[NSMutableParagraphStyle alloc]init];
    contentgraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
    NSDictionary *contentattributes = @{NSFontAttributeName:self.price.font, NSParagraphStyleAttributeName:contentgraphStyle.copy};
    CGSize contenttext=[pricestr boundingRectWithSize:maxszie options:NSStringDrawingUsesLineFragmentOrigin  attributes:contentattributes context:nil].size;
        self.titlewith.constant=(XHScreenwidth-contenttext.width-58-28-30);
    self.dinapu.text=_carmodel.shop_name;
    switch ([_carmodel.sale_type integerValue]) {
        case GANGKOU:
            self.renzheng.image=[UIImage imageNamed:@"ico_hk"];
            break;
        case FOURS:
            self.renzheng.image=[UIImage imageNamed:@"ico_4s"];
            break;
        case PERSONAL:
            self.renzheng.image=[UIImage imageNamed:@"ico_p"];
            
            break;
        case ZIYUAN:
            self.renzheng.image=[UIImage imageNamed:@"ico_z"];
            break;
        case ZONGHE:
            self.renzheng.image=[UIImage imageNamed:@"ico_zonghe"];
            break;
        default:
            break;
    }
}

+(instancetype)cellWithTableView:(UITableView *)tableview{
    static NSString *index=@"index";
    IndexTableviewCell *cell=[tableview dequeueReusableCellWithIdentifier:index];
    if (cell==nil) {
        cell=[[[NSBundle mainBundle] loadNibNamed:@"IndexTableviewCell" owner:nil options:nil] lastObject];
    }
    return cell;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
